package A_review.review1_17;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;


public class Class131 {
      List<List<String>> ans=new ArrayList<>();
        LinkedList<String>  path=new LinkedList<String>();
    public List<List<String>> partition(String s) {
        if (s.length()==0){
            return  ans;
        }
        backTracking(s,0);

        return  ans;
    }

    public  void  backTracking(String s,int start){
        if (start>=s.length()){
            ans.add(new ArrayList<>(path));
        }
        for (int i = start; i < s.length(); i++) {
            if (judge(s,start,i)){
                path.add(s.substring(start,i+1));
            }else {
                continue;
            }
            backTracking(s,i+1);
            path.removeLast();
        }

    }

    public  boolean judge(String s,int start,int end){
         boolean ans=true;
        while (start<=end){
            if (s.charAt(start)==s.charAt(end)){
                start++;
                end--;
            }else {
                ans=false;
                break;
            }

        }
        return  ans;

    }




}
